package com.hmkj.admin.controller.user;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.common.entity.export.ExportUtils;
import com.hmkj.core.model.user.UserFreezeModel;
import com.hmkj.core.po.userFreeze.UserFreeze;
import com.hmkj.core.service.userFreeze.UserFreezeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(BaseController.BASE_URI)
public class UserFreezeJsonController extends GenericController<Integer, UserFreeze> {
    @Resource
    private UserFreezeService userFreezeService;

    /**
     * 用户冻结记录列表数据
     */
    @ResponseBody
    @RequestMapping("userFreeze/list.json")
    @RequiresPermissions("sys:freeze:list")
    public DtGrid listJson(String dtGridPager) throws Exception {
        dtGridPager = dataAuthority(dtGridPager);
        return userFreezeService.getDtGridList(dtGridPager, UserFreezeModel.class);
    }

    /**
     * 修改用户冻结点
     */
    @ResponseBody
    @RequestMapping(value = "userFreeze/edit.json", method = RequestMethod.POST)
    @RequiresPermissions("sys:freeze:edit")
    public ResultEntity doVerify(UserFreeze userFreeze) throws Exception {
        userFreezeService.editFreeze(userFreeze);
        return ok();
    }

    /**
     * 修改
     */
//    @ResponseBody
//    @RequestMapping(value = "userFreeze/json/freeze")
//    @RequiresPermissions("sys:user:freeze:edit")
//    public ResultEntity freeze(UserFreeze userFreeze) throws Exception {
////        UserFreeze oldUserFreeze = userFreezeService.selectOne(new UserFreeze(u -> {
////            u.setId(userFreeze.getId());
////            u.setDelFlag(UserFreeze.DELFLAG.NORMAL.code);
////        }));
//        if (null == oldUserFreeze) {
//            throw new BussinessException("该用户冻结信息不存在");
//        }
//        oldUserFreeze.setFreezingLogin(userFreeze.getFreezingLogin() == null ? UserFreeze.STATUS.T1.code : UserFreeze.STATUS.T2.code);
//        oldUserFreeze.setFreezeRecharge(userFreeze.getFreezeRecharge() == null ? UserFreeze.STATUS.T1.code : UserFreeze.STATUS.T2.code);
//        oldUserFreeze.setFreezeCash(userFreeze.getFreezeCash() == null ? UserFreeze.STATUS.T1.code : UserFreeze.STATUS.T2.code);
//        oldUserFreeze.setFreezeTender(userFreeze.getFreezeTender() == null ? UserFreeze.STATUS.T1.code : UserFreeze.STATUS.T2.code);
//        oldUserFreeze.setRemark(userFreeze.getRemark());
//        userFreezeService.updateByPrimaryKeySelective(userFreeze);
//        return ok();
//    }

    /**
     * 列表导出
     *
     * @param dtGridPager
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "userFreeze/json/export", method = RequestMethod.POST)
    @RequiresPermissions("sys:user:freeze:export")
    public ResultEntity export(String dtGridPager, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 执行导出
        ExportUtils.export(request, response, userFreezeService.getDtGridListExport(dtGridPager, UserFreezeModel.class));
        return ok();
    }

}
